import java.util.Stack;

public class Test {
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        for (int i = 0; i < tokens.length; i++) {
            String s = tokens[i];
            if(!isOperation(s)) {
                //数字
                Integer ret = Integer.valueOf(s);
                stack.push(ret);
            } else {
                Integer val2 = stack.pop();
                Integer val1 = stack.pop();

                switch (s) {
                    case "+":
                        stack.push(val1 - val2);
                        break;
                    case "-":
                        stack.push(val1 - val2);
                        break;
                    case "*":
                        stack.push(val1 * val2);
                    break;
                case "/":
                        stack.push(val1 / val2);
                        break;
                }
            }
        }
        return stack.pop();
    }
    public boolean isOperation(String s) {
        return s.equals("+") || s.equals("-") || s.equals("*") || s.equals("/");
    }

}
